package com.atguigu.gmall.product.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.util.HttpClientUtil;
import com.atguigu.gmall.model.product.BaseAttrInfo;
import com.atguigu.gmall.model.product.BaseCategory1;
import com.atguigu.gmall.model.product.BaseCategory2;
import com.atguigu.gmall.model.product.BaseCategory3;
import com.atguigu.gmall.product.service.ManageService;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//http://localhost/admin/product/getCategory1
@RestController
@RequestMapping("/admin/product")
public class BaseCategoryController {

    @Autowired
    ManageService manageService;

    @GetMapping("/getCategory1")
    public Result getCategory1(){

        List<BaseCategory1> category1 = manageService.getCategory1();
        return Result.ok(category1);
    }
///admin/product/getCategory2/{category1Id}
    @GetMapping("/getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable long category1Id){
        List<BaseCategory2> category2 = manageService.getCategory2(category1Id);
        return Result.ok(category2);
    }
///admin/product/getCategory3/{category2Id}
    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable long category2Id){



        List<BaseCategory3> category3 = manageService.getCategory3(category2Id);

        return Result.ok(category3);
    }

    @GetMapping("attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result<List<BaseAttrInfo>> attrInfoList(@PathVariable("category1Id") Long category1Id,
                                                   @PathVariable("category2Id") Long category2Id,
                                                   @PathVariable("category3Id") Long category3Id) {
        List<BaseAttrInfo> baseAttrInfoList = manageService.getAttrInfoList(category1Id, category2Id, category3Id);
        return Result.ok(baseAttrInfoList);
    }

}
